package com.ugoodtech.mdcc.core.domain;

/* Copyright (C) Ugoodtech, Inc - All Rights Reserved.
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 * Proprietary and confidential.
 * Written by Stone Shaw.
 */

import io.swagger.annotations.ApiModel;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

@ApiModel("通知")
@Entity
@Table(name = "notifications")
public class NotificationMessage extends BaseEntity {

    private MessageTargetCategory targetCategory;
    private Date deliveryTime;
    private String title;
    private String content;
    private Set<User> users;
    private String appLinkId;
    private String externalLink;
    private boolean pushed;
    private User publisher;



    @Enumerated(EnumType.ORDINAL)
    public MessageTargetCategory getTargetCategory() {
        return targetCategory;
    }

    public void setTargetCategory(MessageTargetCategory targetCategory) {
        this.targetCategory = targetCategory;
    }

    public Date getDeliveryTime() {
        return deliveryTime;
    }

    public void setDeliveryTime(Date deliveryTime) {
        this.deliveryTime = deliveryTime;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @ManyToMany(fetch = FetchType.EAGER)
    @Fetch(FetchMode.SELECT)
    @JoinTable(name = "message_client_users",
            joinColumns = {@JoinColumn(name = "message_id")},
            inverseJoinColumns = @JoinColumn(name = "user_id"))
    public Set<User> getUsers() {
        return users;
    }

    public void setUsers(Set<User> users) {
        this.users = users;
    }





    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAppLinkId() {
        return appLinkId;
    }

    public void setAppLinkId(String appLinkId) {
        this.appLinkId = appLinkId;
    }

    public String getExternalLink() {
        return externalLink;
    }

    public void setExternalLink(String externalLink) {
        this.externalLink = externalLink;
    }

    public boolean isPushed() {
        return pushed;
    }

    public void setPushed(boolean pushed) {
        this.pushed = pushed;
    }

    public enum MessageTargetCategory {
        VIP("会员"), NOT_VIP("非会员"), MONTH_VIP("月度会员"), YEAR_VIP("年度会员"), ALL("全部");
        private String name;

        MessageTargetCategory(String name) {
            this.name = name;
        }
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "publisher_id")
    public User getPublisher() {
        return publisher;
    }

    public void setPublisher(User publisher) {
        this.publisher = publisher;
    }
}
